<template>
  <div class="talk">
    <button @click="getLoveTalk">获取土味情话</button>
    <ul>
      <li v-for="item in talkList" :key="item.id">{{ item.title }}</li>
    </ul>
  </div>
</template>

<script setup lang="ts" name="LoveTalk">
import useTalkStore from '@/stores/lovetalk'
import {storeToRefs} from "pinia";

const talkStore = useTalkStore()
let {talkList} = storeToRefs(talkStore)

talkStore.$subscribe((mutate, state) => {
  console.log('talkStore里面保存的数据发生了变化')
  localStorage.setItem('talkList', JSON.stringify(state.talkList))
})

function getLoveTalk() {
  talkStore.getATalk()
}
</script>

<style scoped>
  .talk {
    background-color: orange;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
  }
</style>